package com.yonyou.brigade.third_parties.tujia.service.impl;

import com.yonyou.brigade.basic_init.model.BriChannel;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import com.yonyou.brigade.third_parties.tujia.service.IRegisterService;
import com.yonyou.ybzboot.starter.common.util.R;
import com.yonyou.ybzboot.starter.common.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.Map;

/**
 * @Auther: kfw
 * @Date: 2018/8/23 16:09
 * @Description:
 */
public class RegisterServiceImpl implements IRegisterService {
    @Autowired
    @Qualifier("briChannelServiceImpl")
    private IBriChannelService briChannelService;

    @Override
    public R register(Map<String, String> param) {
        BriChannel briChannel = new BriChannel();
        // 租户为空返回错误
        if (StringUtil.isEmpty(param.get("tenant")))
            return R.error("租户为空");
        else
            briChannel.setTenant(param.get("tenant"));
        if (StringUtil.isEmpty(param.get("orgpk")))
            briChannel.setOpenType(2);
        else {
            briChannel.setOpenType(1);
            briChannel.setOrgpk(param.get("orgpk"));
        }

        briChannel.setChannel("tujia");
        briChannel.setEnable(1);
        briChannel.setConfig(param.get("config"));
        briChannel.setPhone(param.get("phone"));

       if (briChannelService.insert(briChannel))
           return R.ok("开通途家成功");
       else
           return R.error("开通土家失败");
    }
}
